Skip to main content

Leetcode trie Practice Questions

Questions​

1. Implement Trie (Prefix Tree)​

Problem: Implement a trie with insert, search, and startsWith methods.

Link: Implement Trie (Prefix Tree)

2. Add and Search Word - Data structure design​

Problem: Design a data structure that supports adding new words and finding if a string matches any previously added string.

Link: Add and Search Word - Data structure design

3. Longest Word in Dictionary​

Problem: Find the longest word in the dictionary that can be built one character at a time by other words in the dictionary.

Link: Longest Word in Dictionary

4. Replace Words​

Problem: Implement a function to replace all words in a sentence with their root forms using a dictionary of roots.

Link: Replace Words

5. Stream of Characters​

Problem: Design a class to search for strings in a stream of characters.

Link: Stream of Characters

6. Design Search Autocomplete System​

Problem: Implement a search autocomplete system that supports inputting characters and returning the top 3 historical hot sentences.

Link: Design Search Autocomplete System

Problem: Design a class that supports querying words with given prefix and suffix.

Link: Prefix and Suffix Search

8. Word Search II​

Problem: Given a 2D board and a list of words, find all words that can be formed by letters of the board.

Link: Word Search II

9. Map Sum Pairs​

Problem: Implement a MapSum class with insert and sum methods, which sum all keys with a given prefix.

Link: Map Sum Pairs

10. Design Add and Search Words Data Structure​

Problem: Design a data structure that supports adding new words and finding if a string matches any previously added string, with support for wildcards.

Link: Design Add and Search Words Data Structure

11. Palindrome Pairs​

Problem: Given a list of unique words, find all pairs of distinct indices (i, j) such that the concatenation of words[i] and words[j] is a palindrome.

Link: Palindrome Pairs

12. Maximum XOR of Two Numbers in an Array​

Problem: Find the maximum XOR of two numbers in an array.

Link: Maximum XOR of Two Numbers in an Array

13. Concatenated Words​

Problem: Find all concatenated words in a given dictionary of words.

Link: Concatenated Words

14. Design Phone Directory​

Problem: Design a phone directory that initially has all phone numbers available to be assigned and supports checking availability, getting a number, and releasing a number.

Link: Design Phone Directory

15. Search Suggestions System​

Problem: Given an array of products and a search word, design a system that suggests at most 3 products as you type each character of the search word.

Link: Search Suggestions System

16. Word Filter​

Problem: Implement a WordFilter class that supports searching for words with a given prefix and suffix.

Link: Word Filter

17. Index Pairs of a String​

Problem: Given a string text and an array of words, return all index pairs [i, j] so that the substring text[i...j] is in the array of words.

Link: Index Pairs of a String

18. Camelcase Matching​

Problem: Given a list of queries and a pattern, return a list of booleans where each boolean indicates whether the query matches the pattern.

Link: Camelcase Matching

Problem: Implement a class that supports querying words with a given prefix and suffix (similar to question 7 but can be a different version or extension).

Link: Prefix and Suffix Search

20. Delete Duplicate Folders in System​

Problem: Given a system of folders, delete all duplicate folders and return the list of unique folders.

Link: Delete Duplicate Folders in System